package org.rockyang.shardingjdbc.mybatis.common.model;

import lombok.*;
import org.rockyang.shardingjdbc.mybatis.common.utils.Snowflake;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @author yangjian
 */


@Data
public final class Order {


	private Long orderId;

	private Long userId;

	private String title;

	public Order(Long orderId, Long userId) {
		this.orderId = orderId;
		this.userId = userId;
	}

	public Order(Long orderId, Long userId, String title) {
		this.orderId = orderId;
		this.userId = userId;
		this.title = title;
	}

	public static void main(String[] args) {
		List<Long> list = new ArrayList<>();
		for (int i=0;i<5000000;i++){
			long id = Snowflake.getInstance().nextId();
			long a = id % 1163;
			list.add(a);
		}

		Map<Long, List<Long>> collect = list.stream().collect(Collectors.groupingBy(item -> item));

		List<Pair> result = collect.entrySet().stream().map(item -> {
			Long id = item.getKey();
			int num = item.getValue().size();
			return new Pair(id, num);
		}).sorted(Comparator.comparing(Pair::getNum).reversed()).collect(Collectors.toList());
//
//		for (int i=0;i<20;i++){
//			System.out.println("top:"+result.get(i));
//		}
		List<Pair> result2= result.stream().sorted(Comparator.comparing(Pair::getNum)).collect(Collectors.toList());
//		for (int i=0;i<20;i++){
//			System.out.println("end:"+result2.get(i));
//		}
		System.out.println("头尾相差:"+(result.get(0).getNum()-result2.get(0).getNum()));
	}

	@AllArgsConstructor
	@Data
	private static class Pair{
		private Long id;
		private int num;
	}

}
